package ru.payment.wm.impl;

import org.dom4j.Element;
import ru.payment.wm.Operation;
import ru.payment.wm.OperationType;

/**
 *
 * User: sergey
 * Date: 22.04.2009
 * Time: 16:26:27
 *
 */
public class OperationParser extends AbstractResponseParser<Operation, Element> {

  public void parse(Element e, Operation op) throws ProtocolException {

    if (e == null) {
      return;
    }
    
    op.setWmOperationId(e.attributeValue("id"));
    op.setWmTsId(e.attributeValue("ts"));

    op.setTransactionId(asLong(e.element("tranid"), 0));
    op.setPurseSrc(asString(e.element("pursesrc"), ""));
    op.setPurseDest(asString(e.element("pursedest"), ""));
    op.setAmount(asFloat(e.element("amount"), 0f));
    op.setComission(asFloat(e.element("comiss"), 0f));
    int nType = asInt(e.element("opertype"), -1);
    op.setType(OperationType.getByValue(nType));
    op.setPeriod(asInt(e.element("period"), 0));

    op.setWmInvoiceId(asLong(e.element("wminvid"), 0));
    op.setOrderId(asLong(e.element("orderid"), 0));
    op.setDescription(asString(e.element("desc"), ""));
    op.setCreateDate(asDate(e.element("datecrt"), "yyyyMMdd HH:mm:ss"));
    op.setUpdateDate(asDate(e.element("dateupd"), "yyyyMMdd HH:mm:ss"));

    op.setCorrespondentWmId(asString(e.element("corrwm"), ""));
    op.setRest(asFloat(e.element("rest"), 0f));    
  }

}
